//
//  BVMyOrderDetailViewController.m
//  BuyVegetable
//
//  Created by zhuzi on 16/10/14.
//  Copyright © 2016年 com.yinding. All rights reserved.
//  订单详情

#import "BVMyOrderDetailsViewController.h"

#import "BVMyOrderNumberCell.h"
#import "BVMyOrderDetailCell.h"
#import "BVOrderDetailMessageCell.h"
#import "BVServicePhoneButCell.h"

@interface BVMyOrderDetailsViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)UITableView * tableView;
@property (nonatomic,strong)NSArray * arrayMessageTitel;
@property (nonatomic,strong)UIView * notStatusView;
@property (nonatomic,strong)UIView * deliveredStatusView;

@end

@implementation BVMyOrderDetailsViewController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUI];
}
-(UITableView *)tableView{
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH-64-40) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:[BVMyOrderNumberCell class]
           forCellReuseIdentifier:@"orderNumber"];
        [_tableView registerClass:[BVMyOrderDetailCell class] forCellReuseIdentifier:@"orderDetail"];
        [_tableView registerClass:[BVOrderDetailMessageCell class] forCellReuseIdentifier:@"orderDetailMessage"];
        [_tableView registerClass:[BVServicePhoneButCell class] forCellReuseIdentifier:@"servicePhone"];
        
    }
    return _tableView;
}
-(void)setUI{
    
    self.navigationItem.title = @"订单详情";
    
    [self.view addSubview:self.tableView];
    
    [self.view addSubview:self.notStatusView];
    //[self.view addSubview:self.deliveredStatusView];
}
#pragma mark --
#pragma mark ----- UITableViewDelegate,UITableViewDataSource
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return  section == 0 ? 80:5;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return section == 3 ? 10:5;
    
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (section == 0) {
        
        UIImageView * headerImg = [[UIImageView alloc]init];
        headerImg.image = [UIImage imageNamed:@"order_detail_unpay"];
        return headerImg;
    }
    else{
    UIView * view = [[UIView alloc]initWithFrame:self.view.bounds];
    //view.backgroundColor = [UIColor redColor];
    return view;
    }
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    UIView * view = [[UIView alloc]initWithFrame:self.view.bounds];
    //view.backgroundColor = [UIColor blueColor];
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 40;
    }
    else if (indexPath.section == 1){
        return 100;
    }
    else if (indexPath.section == 2){
        if (indexPath.row == 1) {
            return 60;
        }else{
        return 40;
        }
    }
    else{
        return 40;
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0) {
        return 1;
    }
    else if (section == 1){
        
        return 1;
    }
    else if (section == 2){
        return 5;
    }
    else {
    
        return 1;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        BVMyOrderNumberCell * cell = [tableView dequeueReusableCellWithIdentifier:@"orderNumber" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.orderNumberLabel.text = @"订单编号: MC201609090909090909";
        return cell;
    }
    if (indexPath.section == 1) {
         BVMyOrderDetailCell * cell = [tableView dequeueReusableCellWithIdentifier:@"orderDetail" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    else if (indexPath.section == 2){
        BVOrderDetailMessageCell * cell = [tableView dequeueReusableCellWithIdentifier:@"orderDetailMessage" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.titelLabel.text = self.arrayMessageTitel[indexPath.row];
        return cell;
    }
    else{
        BVServicePhoneButCell * cell = [tableView dequeueReusableCellWithIdentifier:@"servicePhone" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.phoneNumber.text = @"客服热线：0531-82897787";
        return cell;
    }
}
-(UIView *)notStatusView{
    
    if (!_notStatusView) {
        
        _notStatusView = [[UIView alloc]init];
        _notStatusView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:_notStatusView];
        _notStatusView.sd_layout.bottomSpaceToView(self.view,0).leftSpaceToView(self.view,0).rightSpaceToView(self.view,0).heightIs(40);
        
        UILabel * priceLabel = [[UILabel alloc]init];
        priceLabel.text = @"¥ 7.20";
        priceLabel.textColor = [UIColor redColor];
        [_notStatusView addSubview:priceLabel];
        priceLabel.sd_layout.topSpaceToView(_notStatusView,0).leftSpaceToView(_notStatusView,10).bottomSpaceToView(_notStatusView,0).widthIs(100);
        
        UIButton * goPayBut = [UIButton buttonWithType:UIButtonTypeSystem];
        goPayBut.backgroundColor = [UIColor BVBaseOrangeColor];
        goPayBut.layer.cornerRadius = 6.0;
        [goPayBut setTitle:@"去付款" forState:UIControlStateNormal];
        [goPayBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_notStatusView addSubview:goPayBut];
        goPayBut.sd_layout.topSpaceToView(_notStatusView,5).rightSpaceToView(_notStatusView,10).bottomSpaceToView(_notStatusView,5).widthIs(80);

        UIButton * cancelBut = [UIButton buttonWithType:UIButtonTypeSystem];
        cancelBut.backgroundColor = [UIColor BVButtonGrayColor];
        cancelBut.layer.cornerRadius = 6.0;
        [cancelBut setTitle:@"取消订单" forState:UIControlStateNormal];
        [cancelBut setTitleColor:[UIColor BVBaseTextBlackColor] forState:UIControlStateNormal];
        [_notStatusView addSubview:cancelBut];
        cancelBut.sd_layout.topSpaceToView(_notStatusView,5).rightSpaceToView(goPayBut,10).bottomSpaceToView(_notStatusView,5).widthIs(80);
    }
    return _notStatusView;
}
-(UIView *)deliveredStatusView{
    
    if (!_deliveredStatusView) {
        
        _deliveredStatusView = [[UIView alloc]init];
        _deliveredStatusView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:_deliveredStatusView];
        _deliveredStatusView.sd_layout.bottomSpaceToView(self.view,0).leftSpaceToView(self.view,0).rightSpaceToView(self.view,0).heightIs(40);
        
        UILabel * priceLabel = [[UILabel alloc]init];
        priceLabel.text = @"¥ 7.20";
        priceLabel.textColor = [UIColor redColor];
        [_deliveredStatusView addSubview:priceLabel];
        priceLabel.sd_layout.topSpaceToView(_deliveredStatusView,0).leftSpaceToView(_deliveredStatusView,10).bottomSpaceToView(_deliveredStatusView,0).widthIs(100);
        
        UIButton * goPayBut = [UIButton buttonWithType:UIButtonTypeCustom];
        goPayBut.backgroundColor = [UIColor BVBaseOrangeColor];
        goPayBut.layer.cornerRadius = 6.0;
        [goPayBut setTitle:@"再来一单" forState:UIControlStateNormal];
        [goPayBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_deliveredStatusView addSubview:goPayBut];
        goPayBut.sd_layout.topSpaceToView(_deliveredStatusView,5).rightSpaceToView(_deliveredStatusView,10).bottomSpaceToView(_deliveredStatusView,5).widthIs(80);
        
    }
    return _deliveredStatusView;
    
}
-(NSArray *)arrayMessageTitel{
    if (!_arrayMessageTitel) {
        _arrayMessageTitel = [NSArray arrayWithObjects:@"收货人:",@"收货地址: ",@"支付方式:",@"下单日期:",@"配送日期:", nil];
    }
    return _arrayMessageTitel;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
